home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 2.iso / BARNET / FREENET / HAWKINS / G0WATCH- / !g0Watch / 3rdParty / ESocket / ReadMe < prev   
Text File  |  1994-10-18  |  11KB  |  304 lines

  1. EasySockets v1.07 (23 Jul 1998)
  2. =========== © Justin Fletcher
  3.  
  4. Introduction
  5. ------------
  6. This module is a simple interface to the Socket handling SWIs. A single module
  7. is supplied, the ESockets module, along with EClient, a simple basic program
  8. that you should run in a taskwindow and provides a 'raw' connection to a
  9. server.
  10.  
  11. Note: SWI chunk is now registered as &51C00.
  12.  
  13.  
  14. Connecting to hosts
  15. -------------------
  16. SYS "ESocket_ConnectToHost",host$,port TO handle
  17.   attempts to connect to a host
  18.  
  19. SYS "ESocket_CheckState",handle TO state
  20.   returns the state of the connection :
  21.     1 we're looking things up
  22.     2 we've looked it up and are trying to connect
  23.     4 we've connected and are ready to go !
  24.    -1 Host lookup failed (no such host)
  25.    -2 Resolver failure (no response, etc)
  26.    -3 Resolver error (it might not be running !)
  27.    -4 No sockets left to create connection
  28.    -5 Host is unreachable
  29.    -6 Connection refused (not listening on that port)
  30.  
  31. SYS "ESocket_Forget",handle
  32.   will forget about a handle
  33.  
  34. SYS "ESocket_DecodeState",state TO name$
  35.   will convert the state number into a textual error string that should
  36.   make more sense.
  37.  
  38. You should use something like the following to connect :
  39.  
  40. SYS "ESocket_ConnectToHost",host$,port TO handle
  41. REPEAT
  42.  SYS "ESocket_CheckState",handle TO state
  43. UNTIL state=4 OR state<0
  44. IF state<0 THEN
  45.  SYS "ESocket_DecodeState",state TO error$
  46.  [give an error]
  47.  SYS "ESocket_Forget",handle
  48. ELSE
  49.  [do things with socket]
  50.  SYS "ESocket_Forget",handle
  51. ENDIF
  52.  
  53.  
  54. Using the sockets
  55. -----------------
  56. SYS "ESocket_SendLine",handle,string$,flags
  57.   sends a line to the other end; flags are :
  58.    bit 0 set if you DON'T want a CR sending
  59.    bit 1 set if you DON'T want a LF sending
  60.    bit 2 set if the string is terminated by a 13 (otherwise 0)
  61.   this means you'd do something like :
  62.    SYS "ESocket_SendLine",handle,"Hello",%000
  63.   most of the time, or :
  64.    SYS "ESocket_SendLine",handle,line,%100
  65.   if you've previously done $line="Hello"
  66.  
  67. SYS "ESocket_ReadLine",handle,buffer,len,flags TO ,buf,len
  68.   which will read a whole line into a buffer, if the buffer
  69.   is not big enough buf is returned as 0 and len as the length
  70.   required, otherwise it's the length of the string.
  71.   return values are therefore :
  72.    buf  len
  73.     0    0   no complete line received yet
  74.     0   any  a line is available of length len (not fitting
  75.              into your buffer)
  76.    any  any  line of length len was read into your buffer
  77.    any   0   zero length line was read into your buffer
  78.   flags is a similar bit map to SendLine :
  79.    bit 0 & 1 can be :
  80.       %00 to use CR LF as a terminator
  81.       %01 to use LF as a terminator
  82.       %10 to use CR as a terminator
  83.       %11 to use either CR or LF as a terminator
  84.    bit 2 should be set to return the data terminated with 13
  85.    rather than 0.
  86.    bit 3 should be set to remove characters deleted with codes
  87.    8 or 127. In this case the returned len is only valid when
  88.    the buffer is. If the buffer is 0, the length is guarenteed
  89.    to be greater than or equal to the true line length.
  90.  
  91. SYS "ESocket_SendData",handle,buffer,len TO sent
  92.   will send a block of data. The amount of data sent is returned.
  93.  
  94. SYS "ESocket_ReadData",handle,buffer,len TO ,,len
  95.   will read a block of data. If buffer = 0 then the length of
  96.   data currently available will be returned in len. If not
  97.   enough data is available then the length of that read is
  98.   returned.
  99.  
  100. SYS "ESocket_Closed",handle,flags TO closed
  101.   returns 1 if the socket has been closed, 0 if not
  102.   flags can be set :
  103.    bit 0 will ignore data in the buffer (useful for ReadLine connections)
  104.  
  105.  
  106. Listening for connections
  107. -------------------------
  108. SYS "ESocket_Listen",port TO handle
  109.   will attempt to listen on a port. However, if an error occurs handle
  110.   will be :
  111.     -4  No sockets left to create connection
  112.     -7  Couldn't listen on that port, something else is
  113.   
  114.   If the port is 0, a new port will be allocated for you.
  115.  
  116. SYS "ESocket_Accept",handle,flags TO newhandle
  117.   will accept a connection on a listening port.
  118.   flags can be :
  119.    bit 0 set to close the listening port after accepting
  120.   newhandle might be returned as :
  121.     -8  Nobody has connected to the port yet
  122.  
  123. You might do something like :
  124.  
  125. SYS "ESocket_Listen",port TO listen
  126. IF listen>0 THEN
  127.  REPEAT
  128.   SYS "ESocket_Accept",listen,%1 TO handle
  129.  UNTIL handle<>-8
  130.  [do stuff with the socket - note that listener has gone]
  131.  SYS "ESocket_Forget",handle
  132. ELSE
  133.  [report listen errors]
  134. ENDIF
  135.  
  136. SYS "ESocket_ConnectionName",handle TO name
  137.   will return 0 if no name is known for that connection, or
  138.   the pointer to a zero terminated name otherwise. Connection
  139.   names are resolved multitaskingly.
  140.  
  141. SYS "ESocket_OurAddress",handle TO ip,port
  142.   will return the address and port number allocated to a socket. Note
  143.   that if you are listening the ip is not likely to be 'correct'.
  144.  
  145.  
  146. Monitors
  147. --------
  148. SYS "ESocket_Monitor",type,... TO monitor
  149.   Monitors are a means by which sockets can be watched for changes without
  150.   having to continually poll them. There can be maybe 'types' of monitors,
  151.   but at present only one is defined :
  152.     type   meaning
  153.      0     checks for input or closure of a socket, and also marks keyboard
  154.            input. Format :
  155.            SYS "ESocket_Monitor",0,handle TO monitor
  156.  
  157. SYS "ESocket_ResetMonitor",monitor,newaddress TO pollword
  158.   is used to reset a monitor back to zero once an active event has been
  159.   identified. If newaddress is 0 then the current address is used.
  160.  
  161. SYS "Esocket_Forget",monitor
  162.   will forget about a monitor.
  163.  
  164. Usually TaskWindow programs will have something like :
  165.  
  166. SYS "ESocket_Monitor",0,handle TO monitor
  167. SYS "ESocket_ResetMonitor",monitor,0 TO polladdr
  168. REPEAT
  169.  SYS "OS_UpCall",6,polladdr
  170.  IF !polladdr THEN
  171.   SYS "ESocket_ResetMonitor",monitor,0
  172.   [process input]
  173.  ENDIF
  174. UNTIL <exit condition>
  175. SYS "ESocket_Forget",monitor
  176.  
  177.  
  178. Additional
  179. ----------
  180. In the interests of ease and stopping people being foolish, EasySocket
  181. will automatically close all sockets and monitors associated with a
  182. particular task on it's exit. This means that you cannot pass socket handles
  183. from one task to another safely, but does mean that in 99.9% of situations
  184. things which have broken can safely exit knowing that they will be tidied up
  185. after.
  186.  
  187. Do not rely on this, it's for your protection, not for your use.
  188.  
  189.  
  190. *Commands
  191. ---------
  192. EasySockets provides two *Commands, *ESockets and *EMonitors.
  193.  
  194. *ESockets
  195.   lists the connections currently made. Information displayed may seem
  196.   technical and probably is.
  197.  
  198. *EMonitors
  199.   lists the monitors currently running. These will reference the handles
  200.   from *ESockets so you'll probably have to use both to understand.
  201.  
  202.  
  203. Resolvers
  204. ---------
  205. ESockets /only/ uses the registered multi-tasking lookup interface to the
  206. resolvers. Because of this it will only work with the Acorn or ANT resolvers.
  207. I will support no other resolvers in this module.
  208.  
  209.  
  210. Comments
  211. --------
  212. I can't actually see that you'd need much more than this in the majority
  213. of internet programs. In fact, if you do need more than this then you
  214. know what you are doing and shouldn't be using it anyhow. However, it's
  215. entirely possible that I've missed something blatantly obvious. If that's
  216. so then could you please contact me and I can beat my head against a
  217. wall :-)
  218.  
  219.  
  220. Bugs
  221. ----
  222. If you RMKill it it'll just leave all it's memory allocated and sockets open.
  223. There's a good reason for this. It's to disuade you from doing it. Ok ?
  224.  
  225.  
  226. Buffering concerns
  227. ------------------
  228. Because of the way in which things are buffered, if you receive a line
  229. containing over 4096 characters without a terminator (one you've asked for)
  230. then the connection will effectively die unless you do a ReadData. The limit
  231. itself is to prevent massive RMA fragmentation and such like. Removing the
  232. limit would allow people almost direct access to your RMA which they could
  233. quite easily fill by just sending lots of junk non-terminated lines.
  234.  
  235. If anyone can suggest a way of coping with this situation I'd like to hear.
  236. My personal favourite I've got is to set a bit in the flags that says 'if
  237. we've reached the maximum size for the buffer and there isn't a terminator in
  238. there then (grin) destroy the lot'. Or possibly '<as above, but don't destroy
  239. it; instead> return it to me as if it was a line'.
  240.  
  241.  
  242. Use of this module
  243. ------------------
  244. Permission for any freeware, shareware or public domain use of EasySockets is
  245. explicitly give. Permission for inclusion in an commercial package or
  246. publication is not given. Contact me for details.
  247.  
  248.  
  249. Contact
  250. -------
  251. Any comments, queries, donations or bug reports can be sent to Justin
  252. Fletcher at :
  253.  
  254. E-Mail : Gerph@innocent.com
  255. URL    : http://www.thevillage.ndirect.co.uk/gerph/
  256. IRC    : On #Acorn as Gerph
  257. Tel    : (01842) 812276
  258.  
  259. Snail Mail :
  260.     Justin Fletcher
  261.     “Galadriel”
  262.     17b Cromwell Road,
  263.     Weeting,
  264.     Brandon,
  265.     Suffolk.
  266.     IP27 0QT
  267.  
  268.  
  269. History
  270. -------
  271. Version 1.00 : 04 Jan 1998
  272.                Began writing module after will-l et al presented an incredibly
  273.                good case for it's existance.
  274. Version 1.01 : 05 Jan 1998
  275.                Finished off most of the outstanding bits (like the code) and
  276.                wrote this documentation.
  277.                Now the only question is 'Do I mail this now, or go to bed ?'
  278. Version 1.02 : 06 Jan 1998 (Release 1, to will-l and with !TalkerD)
  279.                Numerous bug fixed to Listen and Accept.
  280.                Added flags to ESocket_Closed so that we don't lock on
  281.                ReadLines where they send a little data then disconnected.
  282. Version 1.03 : 27 Jan 1998 (Release 2, to will-l and Richard Murray, probably
  283.                on Freenet too)
  284.                Added monitors so that (hopefully) smIRC can be re-compiled
  285.                using ESockets instead of using his sockext library. Maybe then
  286.                it won't suck 99% of the life out of his machine!
  287. Version 1.04 : 29 Jan 1998 (Release 3, as above)
  288.                Fixed CheckState and Closed so that they work with clients that
  289.                don't send any initial message. Set keypressed event on
  290.                TaskWindow_Input so that serial/socket input to a taskwindow
  291.                triggers the pollword.
  292. Version 1.05 : 02 May 1998 (Release 4)
  293.                Fixed bug with Listen, added delete processing to ReadLine.
  294. Version 1.06 : 04 May 1998 (Release 5)
  295.                SWI Base allocated.
  296. Version 1.07 : 23 Jul 1998 (Release 6)
  297.                Non-blocking connections which are 'slow' now work correctly.
  298.                Hopefully this will let IckleRC and MyRC work correctly.
  299.                DecodeState call added for ease.
  300.                OurAddress added for FTP client.
  301.                SendData modified to now return the amount of data sent.
  302.                SendData now returns the amount of data is managed to send.
  303.                *ESockets now gives the textual description of the errors.
  304.